/**
**************************************************************************************
*Palisma - Secrets of the Illuminati is an open-source 2D RPG                        *
*Copyright (C) 2006, Tony Sparks                                                     *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#pragma once

#include <string>
#include <vector>
#include "../shared/geom.h"
#include "../shared/Vector3f.h"
#include "../shared/vector.h"
#include "../render/IRender.h"
#include "../EventManager.h"
#include "GUI_Manager.h"
#include "../script/LUA_Component.h"

namespace gui
{

/**
==========================
Base class for any widget
==========================
*/
class ComponentUI;
class Component
{
public:
    Component(const Component* c);
    Component();

    /** Set/Get the name of this component */
    void SetName( const std::string &s ) { m_name = s; };
    std::string GetName() const { return m_name; };

    /** Set/Get the location */
    void SetLocation( const Vector2f &p ) { m_pos = p; };
    Vector2f GetLocation() const { return m_pos; };

    /** Set/Get the size */
    void SetSize( int w, int h ) { m_width = w; m_height = h; };
    int GetWidth() const { return m_width; };
    int GetHeight() const  { return m_height; };

    /** Set/Get Caption */
    void SetCaption( const std::string &s ) { m_caption = s; };
    std::string GetCaption() const { return m_caption; };

    /** Set/Get background color */
    void SetBackgroundColor( const Vector3f &c ) { m_bColor = c; };
    Vector3f GetBackgroundColor() const { return m_bColor; };

    /** Set/Get Foreground color */
    void SetForegroundColor( const Vector3f &c ) { m_fColor = c; };
    Vector3f GetForegroundColor() const { return m_fColor; };

    /** Set/Get Alpha */
    void SetAlpha( float a ) { m_alpha = a; };
    float GetAlpha() const { return m_alpha; };

    /** Set/Get focus */
    void SetFocus( bool b ) { m_focus = b; };
    bool HasFocus() const { return m_focus; };

    /** Set/Get focus */
    void SetVisible( bool b ) { m_wasVisible = m_visible; m_visible = b; };
    bool IsVisible() const { return m_visible; };

    /** Set/Get owner */
    void SetOwner( const Component* c ) { 
        m_owner = c; 
        if ( m_owner )
        {
            m_pos = m_pos + m_owner->GetLocation();
        }
    };
    const Component* GetOwner() const { return m_owner; };

    /** Add/Remove Listener */
    void AddListener( IEventListener* l ) { RemoveListener(); m_listener = l; };
    void RemoveListener() { m_listener = NULL; };

    /** Add/Remove component */
    void AddComponent( Component* c ) { m_components.push_back( c ); };
    void RemoveComponent( Component* c );

    /** Get a component */
    const Component* GetComponent( Component* c ) const;

    /** un/Install the component UI */
    void InstallUI( ComponentUI* ui );
    void UnistallUI();

    /** Update this component */
    virtual void Update( long dt );
    virtual void Render( IRender* r );
    /** Handle input */
    virtual bool HandleInput();

protected:
    typedef std::vector<Component*> type_ComponentList;
    type_ComponentList  m_components;
    IEventListener*     m_listener;

    const Component*    m_owner;
    Vector3f            m_bColor;
    Vector3f            m_fColor;
    Vector2f            m_pos;
    std::string         m_name;
    std::string         m_caption;


    float               m_alpha;
    bool                m_focus;
    bool                m_visible;
    bool                m_wasVisible;
    int                 m_width;
    int                 m_height;  

    // friends
    friend GUI_Manager;
    friend LUA_Component;
    // var needed for friends
    bool                m_CanRemove;

public:
    virtual ~Component(void);
};

};